﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GiaoTrinhEPU.Repositories.Repositories;
using GiaoTrinhEPU.Core;
using GiaoTrinhEPU.Repositories;
namespace GiaoTrinhEPU.Areas.Manager.Controllers
{

   
    [Authorize(Roles = "Administrator,Manager")] 
    public class BaseController : Controller
    {
        //
        // GET: /Base/
        public BaseController()
        {

            ViewBag.Title = "Manager ! Giao Trinh EPU";
            ViewBag.EnabledMenu = true;
            
        }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var managerMenuRepository = new MenuRepository();

            managerMenuRepository.ClearCache();
            ViewBag.Menus = managerMenuRepository.ListMenus(Role.Manager).ToList();

            base.OnActionExecuting(filterContext);
        }

        protected void PopulateDepartmentDropDownList(int department = -1)
        {
            var departmentManager = new DepartmentRepository();
            var list = departmentManager.ListDepartments().OrderBy(l => l.Id).ToList();

            list.Insert(0, new Department { Id = 0, Name = "Chọn Khoa" });
            ViewBag.DepartmentList = new SelectList(list, "Id", "Name", department);
        }

        protected void PopulateDegreeDropDownList(int degree = -1)
        {
            var degreeManager = new DegreeRepository();
            var list = degreeManager.ListDegrees().OrderBy(l => l.Id).ToList();

            list.Insert(0, new Degree { Id = 0, Name = "Chọn Hệ" });
            ViewBag.DegreeList = new SelectList(list, "Id", "Name", degree);
        }

        protected void PopulateLevelDropDownList(int level = -1)
        {
            var levelManager = new LevelRepository();
            var list = levelManager.ListLevels().OrderBy(l => l.Id).ToList();

            list.Insert(0, new Level { Id = 0, Name = "Chọn Trình Độ" });
            ViewBag.LevelList = new SelectList(list, "Id", "Name", level);
        }
        protected void PopulateWarehouseDropDownList(int wareHouse = -1)
        {
            var wareHouseManager = new WarehouseRepository();
            var list = wareHouseManager.ListWarehouses().OrderBy(l => l.Id).ToList();

            list.Insert(0, new Warehouse { Id = 0, Name = "Chọn Kho" });
            ViewBag.WarehouseList = new SelectList(list, "Id", "Name", wareHouse);
        }
        protected void PopulatePublisherDropDownList(int publisher = -1)
        {
            var publisherManager = new PublisherRepository();
            var list = publisherManager.ListPublishers().OrderBy(l => l.Id).ToList();

            list.Insert(0, new Publisher { Id = 0, Name = "Nhà Xuất Bản" });
            ViewBag.PublisherList = new SelectList(list, "Id", "Name", publisher);
        }


    }
}
